package com.chezhujie.www.service;


import com.chezhujie.www.domain.Classify;
import com.chezhujie.www.persistence.ClassifyMapper;
import com.xy.core.page.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class ClassifyService {
    @Autowired
    private ClassifyMapper classifyMapper;

    public Pagination list(int pageNo, int pageSize, Map<String, Object> params, ModelMap model) throws Exception {

        Pagination pagination = new Pagination();
        pagination.setPageNo(pageNo);
        pagination.setPageSize(pageSize);
        params.putAll(pagination.toMap());
        int count = classifyMapper.getTotalRows(params);
        List<Map<String, Object>> list = classifyMapper.getList(params);
        pagination.setTotalCount(count);
        pagination.setList(list);
        return pagination;
    }


    public void insert(Classify classify){
        classifyMapper.insert(classify);
    }

    public void update(Classify classify){
        classifyMapper.update(classify);
    }
    public void deleteById(String classifyId){
        classifyMapper.deleteById(classifyId);
    }
    public void deleteByIds(List<String> list){
        classifyMapper.deleteByIds(list);
    }
    public Classify queryById(String id){
        return classifyMapper.queryById(id);
    }
    public List<Classify> queryByIds(List<String> list){
        List<Classify> listClassify = classifyMapper.queryByIds(list);
        if(listClassify==null){
            listClassify = new ArrayList<Classify>();
        }
        return listClassify;
    }
}
